package com.ljl.question1;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;

/**
 * 启动类
 *
 * @author ljl
 */
@SpringBootApplication
public class Question1Application {
    private static final Logger logger = LogManager.getLogger(Question1Application.class);

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(Question1Application.class, args);
        // 点对点方式
        MessageChannel inChannel1 = context.getBean("inChannel1", MessageChannel.class);
        inChannel1.send(new GenericMessage<>("hello, world"));
        PollableChannel outChannel1 = context.getBean("outChannel1", PollableChannel.class);
        Message<?> receive = outChannel1.receive(0);
        logger.info("receive msg: " + receive);

        // 发布-订阅方式
        MessageChannel inChannel2 = context.getBean("inChannel2", MessageChannel.class);
        inChannel2.send(new GenericMessage<>("this is ps msg"));
    }

}
